﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace Percolation.Gui
{
    [Serializable]
    public enum GraphicTypeEnum
    {
        [DescriptionAttribute("Average black cells in row by impurity")]
        AvgBlackCellsInRowByImpurity,
        [DescriptionAttribute("Average black cells in column by impurity")]
        AvgBlackCellsInColumnByImpurity,
        [DescriptionAttribute("Average null row count by impurity")]
        AvgNullRowCountByImpurity,
        [DescriptionAttribute("Average null column count by impurity")]
        AvgNullColumnCountByImpurity,
        [DescriptionAttribute("Average black cells count by impurity")]
        AvgBlackCellsCountByImpurity,
        [DescriptionAttribute("Average cluster count by impurity")]
        AvgClusterCountByImpurity,
        [DescriptionAttribute("Average cluster size by impurity")]
        AvgClusterSizeByImpurity,
        [DescriptionAttribute("Percolation probability by impurity")]
        PercolationProbabilityByImpurity,
        [DescriptionAttribute("Average percolation cluster size by impurity")]
        AvgPercolationClusterSizeByImpurity,
        [DescriptionAttribute("Average added cells count by impurity")]
        AvgAddedCellsCountByImpurity,
        [DescriptionAttribute("Average route length by impurity")]
        AvgRouteLengthByImpurity,
        [DescriptionAttribute("Average route between clusters by impurity")]
        AvgRouteClustersByImpurity,
        [DescriptionAttribute("Max route between clusters by impurity")]
        MaxRouteClustersByImpurity,
        [DescriptionAttribute("Average added cells concentration by impurity")]
        AvgAddedCellsConcentrationByImpurity
    }

    [Serializable]
    public class Graphic
    {
        public GraphicTypeEnum Type { get; set; }
        public List<int> RangeNums { get; private set; }

        protected PercolationProject m_project;

        public Graphic(PercolationProject project, GraphicTypeEnum type, List<int> rangeNums)
        {
            Type = type;
            RangeNums = rangeNums;
            m_project = project;
        }

        public int getCaptionXCount()
        {
            return 11;
        }


        public int getCaptionYCount()
        {
            return 6;
        }


        public double getStartX(int rangeNum)
        {
            return 0;
        }

        public double getStartY(int rangeNum)
        {
            switch (Type)
            {
                case GraphicTypeEnum.AvgBlackCellsInRowByImpurity:
                    return 0;
                case GraphicTypeEnum.AvgBlackCellsInColumnByImpurity:
                    return 0;
                case GraphicTypeEnum.AvgNullRowCountByImpurity:
                    return m_project.Ranges[rangeNum].Settings.NetHeight;
                case GraphicTypeEnum.AvgNullColumnCountByImpurity:
                    return m_project.Ranges[rangeNum].Settings.NetWidth;
                case GraphicTypeEnum.AvgBlackCellsCountByImpurity:
                    return 0;
                case GraphicTypeEnum.AvgClusterCountByImpurity:
                    return 0;
                case GraphicTypeEnum.AvgClusterSizeByImpurity:
                    return 0;
                case GraphicTypeEnum.PercolationProbabilityByImpurity:
                    return 0;
                case GraphicTypeEnum.AvgPercolationClusterSizeByImpurity:
                    return 0;
                case GraphicTypeEnum.AvgAddedCellsCountByImpurity:
                    return m_project.Ranges[rangeNum].Settings.NetHeight;
                case GraphicTypeEnum.AvgRouteLengthByImpurity:
                    return m_project.Ranges[rangeNum].Settings.NetHeight;
                case GraphicTypeEnum.AvgRouteClustersByImpurity:
                    return 0;
                case GraphicTypeEnum.MaxRouteClustersByImpurity:
                    return 0;
                case GraphicTypeEnum.AvgAddedCellsConcentrationByImpurity:
                    return 1.0;
                default:
                    return 0;
            }
        }

        public double getEndX(int rangeNum)
        {
            return 1;
        }

        public double getEndY(int rangeNum)
        {
            switch (Type)
            {
                case GraphicTypeEnum.AvgBlackCellsInRowByImpurity:
                    return m_project.Ranges[rangeNum].Settings.NetWidth;
                case GraphicTypeEnum.AvgBlackCellsInColumnByImpurity:
                    return m_project.Ranges[rangeNum].Settings.NetHeight;
                case GraphicTypeEnum.AvgNullRowCountByImpurity:
                    return 0;
                case GraphicTypeEnum.AvgNullColumnCountByImpurity:
                    return 0;
                case GraphicTypeEnum.AvgBlackCellsCountByImpurity:
                    return m_project.Ranges[rangeNum].Settings.NetHeight * m_project.Ranges[rangeNum].Settings.NetWidth;
                case GraphicTypeEnum.AvgClusterCountByImpurity:
                    return 1;
                case GraphicTypeEnum.AvgClusterSizeByImpurity:
                    return m_project.Ranges[rangeNum].Settings.NetHeight * m_project.Ranges[rangeNum].Settings.NetWidth;
                case GraphicTypeEnum.PercolationProbabilityByImpurity:
                    return 1;
                case GraphicTypeEnum.AvgPercolationClusterSizeByImpurity:
                    return m_project.Ranges[rangeNum].Settings.NetHeight * m_project.Ranges[rangeNum].Settings.NetWidth;
                case GraphicTypeEnum.AvgAddedCellsCountByImpurity:
                    return 0;
                case GraphicTypeEnum.AvgRouteLengthByImpurity:
                    return m_project.Ranges[rangeNum].Settings.NetHeight;
                case GraphicTypeEnum.AvgRouteClustersByImpurity:
                    return 0;
                case GraphicTypeEnum.MaxRouteClustersByImpurity:
                    return 0;
                case GraphicTypeEnum.AvgAddedCellsConcentrationByImpurity:
                    return 0;
                default:
                    return 1.0;
            }
        }


        public String getCaptionX()
        {
            return "i";
        }

        public String getCaptionY()
        {
            switch (Type)
            {
                case GraphicTypeEnum.AvgBlackCellsInRowByImpurity:
                    return "abcr";
                case GraphicTypeEnum.AvgBlackCellsInColumnByImpurity:
                    return "abcc";
                case GraphicTypeEnum.AvgNullRowCountByImpurity:
                    return "anrc";
                case GraphicTypeEnum.AvgNullColumnCountByImpurity:
                    return "ancc";
                case GraphicTypeEnum.AvgBlackCellsCountByImpurity:
                    return "abc";
                case GraphicTypeEnum.AvgClusterCountByImpurity:
                    return "acc";
                case GraphicTypeEnum.AvgClusterSizeByImpurity:
                    return "acs";
                case GraphicTypeEnum.PercolationProbabilityByImpurity:
                    return "pp";
                case GraphicTypeEnum.AvgPercolationClusterSizeByImpurity:
                    return "apcs";
                case GraphicTypeEnum.AvgAddedCellsCountByImpurity:
                    return "aac";
                case GraphicTypeEnum.AvgRouteLengthByImpurity:
                    return "arl";
                case GraphicTypeEnum.AvgRouteClustersByImpurity:
                    return "arc";
                case GraphicTypeEnum.MaxRouteClustersByImpurity:
                    return "mrc";
                case GraphicTypeEnum.AvgAddedCellsConcentrationByImpurity:
                    return "aacc";
                default:
                    return " none";
            }
        }
    }

    [Serializable]
    public class PercolationProject
    {
        public ProjectSettings Settings { get; private set; }
        public List<ExperimentsRange> Ranges { get; private set; }
        public List<Graphic> Graphics { get; private set; }
        public String Name { get; private set; }

        public PercolationProject(String name)
        {
            Name = name;
            Settings = new ProjectSettings();
            Ranges = new List<ExperimentsRange>();
            Graphics = new List<Graphic>();
        }
    }
}
